#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include "Spline.h"
#include <jsoncpp/json/json.h>
using namespace std;

int main()
{
    Json::Reader reader;
    Json::Value root;
    ofstream fout;
    ifstream in("questionE.json", ios::binary);
    vector<int> Num;
    if (reader.parse(in, root))
	{
        for (int i = 0; i < root["n"].size(); i++)
	    {
	        int num = root["n"][i].asInt();
	        Num.push_back(num);
	    }
    }

    for (int i = 0; i < Num.size(); i++)
	{
        vector<vector<double>> T;
        vector<double> V;
        int num1 = floor((Num[i] - 4.0) / 4.0);
        int num2 = floor((Num[i] - 4.0) / 2.0) - num1;
        V.push_back(0.0);
        V.push_back(sqrt(3.0) * 2.0 / 3.0);
        T.push_back(V);
        V.clear();
        for (int j = 1; j <= num1; j++)
        {
            vector<double> temp_T;
            double x = j * sqrt(3.0) / (num1 + 1.0);
            temp_T.push_back(x);
            temp_T.push_back((sqrt(3.0 - x * x) + sqrt(fabs(x))) * 2.0 / 3.0);
            T.push_back(temp_T);
        }
        V.push_back(sqrt(3.0));
        V.push_back(sqrt(sqrt(3.0)) * 2.0 / 3.0);
        T.push_back(V);
        V.clear();
        for (int j = 1; j <= num2; j++)
        {
            vector<double> temp_T;
            double x = sqrt(3.0) - j * sqrt(3.0) / (num2 + 1.0);
            temp_T.push_back(x);
            temp_T.push_back((-sqrt(3.0 - x * x) + sqrt(fabs(x))) * 2.0 / 3.0);
            T.push_back(temp_T);
		}
        V.push_back(0.0);
        V.push_back(-sqrt(3.0) * 2.0 / 3.0);
        T.push_back(V);
        V.clear();
        for (int j = 1; j <= num2; j++)
        {
            vector<double> temp_T;
            double x = -j * sqrt(3.0) / (num2 + 1.0);
            temp_T.push_back(x);
            temp_T.push_back((-sqrt(3.0 - x * x) + sqrt(fabs(x))) * 2.0 / 3.0);
            T.push_back(temp_T);
        }
        V.push_back(-sqrt(3.0));
        V.push_back(sqrt(sqrt(3.0)) * 2.0 / 3.0);
        T.push_back(V);
        V.clear();
        for (int j = 1; j <= num1; j++)
		{
            vector<double> temp_T;
            double x = -sqrt(3.0) + j * sqrt(3.0) / (num1 + 1.0);
            temp_T.push_back(x);
            temp_T.push_back((sqrt(3.0 - x * x) + sqrt(fabs(x))) * 2.0 / 3.0);
            T.push_back(temp_T);
        }
        V.push_back(0.0);
        V.push_back(sqrt(3.0) * 2.0 / 3.0);
        T.push_back(V);
        V.clear();
        Curvespline Curve(T, 1, 3);
        Curve.solve();
        vector<vector<double>> xy = Curve.Get_X();
        cout << "N = " << Num[i] << endl;
        for (int j = 0; j < xy.size(); j++)
		{
            for (int k = 0; k < xy[j].size() - 1; k++)
            {
                cout << xy[j][k] << ",";
            }
            cout << xy[j][xy[j].size() - 1] << endl;
        }
	}
    return 0;
}
